package com.lonty.intelligence.controller;

import com.lonty.intelligence.api.Result;
import com.lonty.intelligence.api.ResultCode;
import com.lonty.intelligence.service.LeavingMessageService;
import com.lonty.intelligence.vo.LeavingMessageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author 陈璇
 * @Date 2020/6/11 13:13
 * @Version 1.0
 */
@RestController
@RequestMapping("app/leavingMessage")
@Validated
@Api(tags = "留言接口", produces = "application/json")
public class LeavingMessageController {

    @Resource
    private LeavingMessageService leavingMessageService;

    @ApiOperation(value = "保存留言", httpMethod = "POST")
    @PostMapping("saveLeavingMessage")
    public Result saveLeavingMessage(@ModelAttribute LeavingMessageVo leavingMessageVo){
        if(leavingMessageService.saveLeavingMessage(leavingMessageVo)){
            return Result.builder().build();
        }
        return Result.builder(ResultCode.OPERATION_ERROR).build();
    }

    @ApiOperation(value = "根据ID获取留言", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "留言ID",dataType = "string", paramType = "query", required = true)
    })
    @GetMapping("getById")
    public Result getById(String id){
        return Result.builder()
                .data(leavingMessageService.getById(id))
                .build();
    }

    @ApiOperation(value = "根据用户ID获取留言", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userInfoId", value = "用户ID",dataType = "string", paramType = "query", required = true)
    })
    @GetMapping("getByUserId")
    public Result getByUserId(String userInfoId){
        return Result.builder()
                .data(leavingMessageService.getByUserId(userInfoId))
                .build();
    }

    @ApiOperation(value = "获取社区所有留言", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "communityId", value = "社区ID",dataType = "string", paramType = "query", required = true)
    })
    @GetMapping("getLeavingMessageAndUser")
    public Result getLeavingMessageAndUser(String communityId){
        return Result.builder()
                .data(leavingMessageService.getLeavingMessageAndUser(communityId))
                .build();
    }

}
